//
//  AY_ReadChapterCell.m
//  AiYue
//
//  Created by mac on 2023/10/25.
//

#import "AY_ReadChapterCell.h"

@interface AY_ReadChapterCell ()

@property (nonatomic,strong) UILabel *chapterLabel;
@property (nonatomic,strong) UIImageView *readLockImg; // 阅读锁img

@end

@implementation AY_ReadChapterCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self)
    {
        self.contentView.backgroundColor = COLOR([AYMMKV getStringForKey:ReadToolBackColor defaultValue:@"FEF6E9"]);
        
        self.readLockImg = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"AY_lock") andBg:nil andRadius:0 andAddSubView:self.contentView];
        [self.readLockImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-YNUM(20));
            make.width.height.mas_equalTo(YNUM(20));
        }];
        
        self.chapterLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR([AYMMKV getStringForKey:ReadTitleColor defaultValue:@"422D10"]) andBgColor:nil andFont:YFont(14) andLines:1 andRadius:0 andAddSubView:self.contentView];
        [self.chapterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.readLockImg.mas_left).offset(-YNUM(15));
            make.left.equalTo(self.contentView).offset(YNUM(20));
        }];
        
        [self.contentView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]];
        
    }
    return self;
}

- (void)setModel:(ReadChapterModel *)model {
    _model = model;
    if ([model.isRead isEqual:@"1"]) {
        self.chapterLabel.textColor = [UIColor redColor];
    }else {
        self.chapterLabel.textColor = COLOR([AYMMKV getStringForKey:ReadTitleColor defaultValue:@"422D10"]);
    }
    self.chapterLabel.text = model.title;
    self.contentView.backgroundColor = COLOR([AYMMKV getStringForKey:ReadToolBackColor defaultValue:@"FEF6E9"]);
    if ([model.chargeFlag isEqual:@"0"]) {
        self.readLockImg.hidden = YES;
    }else {
        self.readLockImg.hidden = NO;
    }
}

-(void)tap
{
    if ([self.delegate respondsToSelector:@selector(didSelectCharpterWithIndex:andChapterIndex:)]) {
        [self.delegate didSelectCharpterWithIndex:self.model andChapterIndex:self.indexRow];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
